package com.zjw.zy.utils;

import static android.content.Context.MODE_PRIVATE;

import android.content.SharedPreferences;

import com.tencent.mmkv.MMKV;

import java.util.Set;

/**
 * @author ：zhong.jw
 * @date ：Created in 2022/9/27 11:20
 */
public final class SharePrefUtils {

    public static final String SHARE_PREF_NAME = "SHARE_PREF_NAME";

    public static void putString(String key, String value) {
        defaultMMKV().putString(key, value).apply();
    }

    public static void putStringIfNotEmpty(String key, String value) {
        if (value == null || "".equals(value)) {
            return;
        }
        putString(key, value);
    }

    public static void putInt(String key, int value) {
        defaultMMKV().putInt(key, value).apply();
    }


    public static void putBoolean(String key, boolean value) {
        defaultMMKV().putBoolean(key, value).apply();
    }

    public static void putFloat(String key, float value) {
        defaultMMKV().putFloat(key, value).apply();
    }

    public static void putLong(String key, long value) {
        defaultMMKV().putLong(key, value).apply();
    }

    public static void putStringSet(String key, Set<String> value) {
        defaultMMKV().putStringSet(key, value).apply();
    }

    public static String getString(String key, String defaultValue) {
        return defaultMMKV().getString(key, defaultValue);
    }

    public static int getInt(String key, int defaultValue) {
        return defaultMMKV().getInt(key, defaultValue);
    }

    public static boolean contain(String key) {
        return defaultMMKV().contains(key);
    }


    public static boolean getBoolean(String key, boolean defaultValue) {
        return defaultMMKV().getBoolean(key, defaultValue);
    }

    public static float getFloat(String key, float defaultValue) {
        return defaultMMKV().getFloat(key, defaultValue);
    }

    public static long getLong(String key, long defaultValue) {
        return defaultMMKV().getLong(key, defaultValue);
    }

    public static Set<String> getStringSet(String key, Set<String> defaultValue) {
        return defaultMMKV().getStringSet(key, defaultValue);
    }

    private static MMKV defaultMMKV() {
        return MMKV.defaultMMKV();
    }

}
